package com.geek;

import com.geek.busness.handler.MyKeyboardEventHandler;
import com.geek.busness.handler.MyMouseEventHandler;
import com.geek.monitor.KeyboardHook;
import com.geek.monitor.MouseHook;
import com.geek.ui.FrameUpdater;
import lombok.extern.slf4j.Slf4j;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

@Slf4j
public class Monitor  {

	public Monitor()  {
		boolean [] on_off={true};
		//监听进程
//		new Thread(new ProcessInfo(on_off)).start();

		log.info("1");
		log.debug("2");
		log.warn("3");
		log.error("4");

		if(true){
			return;
		}

		FrameUpdater.openWindow();

		//监听键盘
		new Thread(new KeyboardHook(on_off, new MyKeyboardEventHandler())).start();

		//监听鼠标
		new Thread(new MouseHook(on_off, new MyMouseEventHandler())).start();

		//显示托盘图标
		final TrayIcon trayIcon;
		if (SystemTray.isSupported()) {

			SystemTray tray = SystemTray.getSystemTray();
			Image image = Toolkit.getDefaultToolkit().getImage("D:////test//monitor.bmp");

			ActionListener exitListener = new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					System.out.println("Exiting...");
					System.exit(0);
				}
			};

			PopupMenu popup = new PopupMenu();
			MenuItem defaultItem = new MenuItem("Exit");
			defaultItem.addActionListener(exitListener);
			popup.add(defaultItem);

			trayIcon = new TrayIcon(image, "monitor", popup);

			ActionListener actionListener = new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					trayIcon.displayMessage("Action Event",
							"An Action Event Has Been Peformed!",
							TrayIcon.MessageType.INFO);
				}
			};

			trayIcon.setImageAutoSize(true);
			trayIcon.addActionListener(actionListener);

			try {
				tray.add(trayIcon);
			} catch (AWTException e1) {
				e1.printStackTrace();
			}
		}
	}

	public static void main(String[] args)  {
		new Monitor();
	}

}